package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    @Select("select *from address_book where user_id=#{userId}")
    public List<AddressBook> list_addressBook(Long userId);

    void save(AddressBook addressBook);

    @Select("SELECT *FROM address_book WHERE user_id=#{userId} and is_default=true")
    public AddressBook defaults(Long userId);

    void update(AddressBook addressBook);


    @Select("SELECT *FROM address_book WHERE ID=#{id}")
    AddressBook getById(Long id);

    @Delete("DELETE FROM address_book WHERE id=#{id}")
    void deleteById(Long id);

    @Update("UPDATE address_book SET is_default=true WHERE id=#{id}")
    public void setDefault(Long id);

    @Update("UPDATE  address_book SET is_default=false where user_id=#{userId}")
    void setAllDefaultFalse(Long userId);
}
